AzCastBarDropDowns = {};
local cfg = AzCastBar_Config;

-- Shared Media
local LSM = LibStub and LibStub("LibSharedMedia-3.0",1);

-- DropDown Lists
AzCastBarDropDowns.FontFlags = {
	["None"] = "",
	["Outline"] = "OUTLINE",
	["Thick Outline"] = "THICKOUTLINE",
};

--------------------------------------------------------------------------------------------------------
--                                        Default DropDown Init                                       --
--------------------------------------------------------------------------------------------------------

local function Default_SelectValue(dropDown,table)
	cfg[AzCastBarOptions.activeBar.token][dropDown.option.var] = table.value;
	AzCastBar.ApplyBarSettings(AzCastBarOptions.activeBar);
end

function AzCastBarDropDowns.Default(dropDown,table)
	dropDown.SelectValueFunc = Default_SelectValue;
	for text, option in pairs(dropDown.option.list) do
		tinsert(table,{ text = text, value = option });
	end
end

--------------------------------------------------------------------------------------------------------
--                                          Lib Shared Media                                          --
--------------------------------------------------------------------------------------------------------

if (LSM) then
	LSM:Register("border","Solid","Interface\\Buttons\\WHITE8X8");
end

local LibSharedMediaSubstitute = not LSM and {
	["font"] = {
		["Friz Quadrata TT"] = "Fonts\\FRIZQT__.TTF",
		["Arial Narrow"] = "Fonts\\ARIALN.TTF",
		["Skurri"] = "Fonts\\SKURRI.TTF",
		["Morpheus"] = "Fonts\\MORPHEUS.TTF",
	},
	["background"] = {
		["Blizzard Tooltip"] = "Interface\\Tooltips\\UI-Tooltip-Background",
		["Solid"] = "Interface\\Buttons\\WHITE8X8",
	},
	["border"] = {
		["None"] = "Interface\\None",
		["Blizzard Dialog"]  = "Interface\\DialogFrame\\UI-DialogBox-Border",
		["Blizzard Tooltip"] = "Interface\\Tooltips\\UI-Tooltip-Border",
		["Solid"] = "Interface\\Buttons\\WHITE8X8",
	},
	["statusbar"] = {
		["Blizzard StatusBar"] = "Interface\\TargetingFrame\\UI-StatusBar",
	},
} or nil;

do
	local AZCB_Textures = {
		"HorizontalFade",
		"Pale",
		"Lines",
		"SmoothBar",
		"Streamline",
		"Streamline-Inverted",
		"Waterline",
	};
	local texturePath;
	local root = "Interface\\Addons\\AzCastBar\\Textures\\";
	for _, texture in ipairs(AZCB_Textures) do
		texturePath = root..texture;
		if (LSM) then
			LSM:Register("statusbar","|cffffff00"..texture,texturePath);
		else
			LibSharedMediaSubstitute["statusbar"][texture] = texturePath;
		end
	end
end

function AzCastBarDropDowns.SharedMediaLib(dropDown,table)
	local query = dropDown.option.media;
	dropDown.SelectValueFunc = Default_SelectValue;
	if (LSM) then
		for _, name in pairs(LSM:List(query)) do
			tinsert(table,{ text = name, value = LSM:Fetch(query,name) });
		end
	else
		for name, value in pairs(LibSharedMediaSubstitute[query]) do
			tinsert(table,{ text = name, value = value });
		end
	end
end